<?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Address extends Model
{
    protected $table = 'address';
    protected $guarded = [];
    protected $dateFormat = 'U';
    public $timestamps = false;
    public function wxuser()
    {
        return $this->belongsTo('App\Models\Wxuser');
    }

    public function setDefault($id){
        $this->default=1;
        if($this->save()){
            $count = self::where('id','<>',$this->id)->where('wxuser_id',$id)->update(['default' => 0]);
            return $count?true:false;
        }else{
            return false;
        }
    }
    public function default($uid,$default){
        $this->default=$default;
        if($default==1)
            self::where('id','<>',$this->id)->where('wxuser_id',$uid)->update(['default' => 0]);
        return $this->save();
    }
}
